package com.arcvideo.acsplayer.preference;

import android.content.Context;
import android.content.SharedPreferences;

public class SharePreferenceUtil {
	public static final String MESSAGE_NOTIFY_KEY = "message_notify";
	public static final String MESSAGE_SOUND_KEY = "message_sound";
	public static final String SHOW_HEAD_KEY = "show_head";
	public static final String PULLREFRESH_SOUND_KEY = "pullrefresh_sound";

	public static final String USER_NAME = "user_name";
	public static final String USER_PASSWORD = "user_password";
	public static final String SERVER_ADDRESS = "server_address";
	public static final String URL_DEFAULT = "url_default";
	public static final String URL_LAST_PLAYED = "url_last_played";
	public static final String TITLE_LAST_PLAYED = "title_last_played";

	private SharedPreferences sp;
	private SharedPreferences.Editor editor;

	public SharePreferenceUtil(Context context, String file) {
		sp = context.getSharedPreferences(file, Context.MODE_PRIVATE);
		editor = sp.edit();
	}

	// 得到登陆名字
	public String getLoginUserName() {
		return sp.getString(USER_NAME, "");
	}

	public void setLoginUserName(final String userName) {
		editor.putString(USER_NAME, userName);
		editor.commit();
	}

	// 得到登陆密码
	public String getLoginUserPassword() {
		return sp.getString(USER_PASSWORD, "");
	}

	public void setLoginUserPassword(final String password) {
		editor.putString(USER_NAME, password);
		editor.commit();
	}

	// 得到服务器地址
	public String getLoginServerAddress() {
		return sp.getString(SERVER_ADDRESS, "");
	}

	public void setLoginServerAddress(final String serverAddress) {
		editor.putString(SERVER_ADDRESS, serverAddress);
		editor.commit();
	}

	// 得到服务器地址
	public String getDefaultUrl() {
		return sp.getString(URL_DEFAULT, "");
	}

	public void setDefaultUrl(final String defaultUrl) {
		editor.putString(URL_DEFAULT, defaultUrl);
		editor.commit();
	}

	public String getLastPlayedTitle() {
		return sp.getString(TITLE_LAST_PLAYED, "");
	}

	public void setLastPlayedTitle(final String lastPlayedTitle) {
		editor.putString(TITLE_LAST_PLAYED, lastPlayedTitle);
		editor.commit();
	}
	public String getLastPlayedUrl() {
		return sp.getString(URL_LAST_PLAYED, "");
	}

	public void setLastPlayedUrl(final String lastPlayedUrl) {
		editor.putString(URL_LAST_PLAYED, lastPlayedUrl);
		editor.commit();
	}

	// 设置Tag
	public void setTag(String tag) {
		editor.putString("tag", tag);
		editor.commit();
	}

	public String getTag() {
		return sp.getString("tag", "");
	}

	// 是否通知
	public boolean getMsgNotify() {
		return sp.getBoolean(MESSAGE_NOTIFY_KEY, true);
	}

	public void setMsgNotify(boolean isChecked) {
		editor.putBoolean(MESSAGE_NOTIFY_KEY, isChecked);
		editor.commit();
	}

	// 新消息是否有声音
	public boolean getMsgSound() {
		return sp.getBoolean(MESSAGE_SOUND_KEY, true);
	}

	public void setMsgSound(boolean isChecked) {
		editor.putBoolean(MESSAGE_SOUND_KEY, isChecked);
		editor.commit();
	}

	// 刷新是否有声音
	public boolean getPullRefreshSound() {
		return sp.getBoolean(PULLREFRESH_SOUND_KEY, true);
	}

	public void setPullRefreshSound(boolean isChecked) {
		editor.putBoolean(PULLREFRESH_SOUND_KEY, isChecked);
		editor.commit();
	}
}